/*
 * GammaEliasFede_gtest.h
 *
 *  Created on: Dec 15, 2012
 *      Author: Federico Orquera
 */

#ifndef GAMMAELIASFEDE_GTEST_H_
#define GAMMAELIASFEDE_GTEST_H_

#include <vector>
#include <cstring>
#include <gtest/gtest.h>

#include "../physical_layer/serializers/InvertedListSerializer.h"
#include "../physical_layer/file_system/InvertedList.h"

using physical::byte;
using physical::InvertedList;
using physical::InvertedListSerializer;
using physical::InvalidSizeException;

#include "../physical_layer/common_components/physical_layer_commons.h"
#include "../physical_layer/compresorGammaElias/ColeccionDeBits.h"
#include "../physical_layer/compresorGammaElias/GammaElias.h"

class GammaEliasFedeTestFixture: public testing::Test {
public:
	std::string m_fileName;

	GammaEliasFedeTestFixture()
	{
		const ::testing::TestInfo* const test_info =
				::testing::UnitTest::GetInstance()->current_test_info();

		std::string filename(test_info->name());
		filename.append(".");
		filename.append(test_info->test_case_name());
		filename.append(".tmp");

		this->m_fileName = filename;
	}

    void SetUp(){}

    void TearDown(){}

	virtual ~GammaEliasFedeTestFixture(){}

    const char* getFileNameForTest() {
        return m_fileName.c_str();
    }

    // put in any custom data members that you need
   InvertedListSerializer m_serializer;
};


TEST_F( GammaEliasFedeTestFixture, PruebaCompressAndUncompressConInvertedListSerializer ){

	InvertedList invertedList = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
	InvertedList deserializedInvertedList;
	size_t expectedSerializationBytes;
	size_t serializedBytes;
	size_t deserializedBytes;
	byte buffer[128];
	//byte compressedBuffer[128];
	//byte uncompressedBuffer[128];

	expectedSerializationBytes = m_serializer.getSize( invertedList );

	serializedBytes = m_serializer.serialize( invertedList, buffer );

	/**
	 * El gamma de Elias tiene que pasar esta prueba, que es una fraccion de lo que hace el programa.
	 * La parte comentada es la que tenes que hacer andar.
	 * Descomenta el codigo que tiene todo lo de gamma de elias y comenta la linea que esta marcada.
	 * Esto lo dejo asi, pq si dejo tu codigo tira segmentation fault.
	 */

	/*
	GammaElias ge=GammaElias();

	auto tamanioResultanteComprimido = ge.compress(buffer,compressedBuffer,serializedBytes);

	auto tamanioResultanteDescomprimido = ge.uncompress(compressedBuffer,uncompressedBuffer,tamanioResultanteComprimido);

	ASSERT_EQ( serializedBytes, tamanioResultanteDescomprimido );

	deserializedBytes = m_serializer.deserialize( uncompressedBuffer, deserializedInvertedList );
	*/
	/***/

	deserializedBytes = m_serializer.deserialize( buffer, deserializedInvertedList ); // <-- Esta linea tiene que estar comentada

	ASSERT_EQ( expectedSerializationBytes, size_t(22) );
	ASSERT_EQ( serializedBytes, size_t(22) );
	ASSERT_EQ( deserializedBytes, size_t(22) );
	ASSERT_EQ( invertedList, deserializedInvertedList );

}

#endif /* GAMMAELIASFEDE_GTEST_H_ */
